package com.youchuang.action.admin;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Book;
import com.youchuang.bean.CategoryProduct;
import com.youchuang.common.Constant;
import com.youchuang.service.AdminService;
import com.youchuang.service.MainService;

/**
 * 管理员查看图书的详细信息
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/admin")
@ParentPackage("shopping-default")
public class BookContextAction extends BaseAction {
	private static Logger logger = Logger.getLogger(BookContextAction.class.getSimpleName());
	private Book book;
	private String id;
	private String cname1;
	private String cname2;
	@Resource
	private AdminService adminService;
	@Resource
	private MainService mainService;

	@Action(value = "bookContext", results = {
			@Result(name = Constant.SUCCESS, location = "/WEB-INF/jsp/ad/bookcontext.jsp") })
	public String execute() throws Exception {
		logger.info("method is execute");
		book = mainService.findBookById(id);
		List<CategoryProduct> categoryProducts = adminService.findCategoryByProductIdSort(id);

		cname1 = adminService.findCategoryNameByCategoryId(categoryProducts.get(0).getCategoryId());
		cname2 = adminService.findCategoryNameByCategoryId(categoryProducts.get(1).getCategoryId());
		return Constant.SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public String getCname1() {
		return cname1;
	}

	public void setCname1(String cname1) {
		this.cname1 = cname1;
	}

	public String getCname2() {
		return cname2;
	}

	public void setCname2(String cname2) {
		this.cname2 = cname2;
	}

}
